package main

import (
	"math/rand"
	"sync"
	"time"
)

func myjobs() {
	println(rand.Intn(100))
}
func main() {
	mg := sync.WaitGroup{}
	maxnum := make(chan struct{}, 5)
	go func() {
		for {
			mg.Wait()
			for i := 0; i < 5; i++ {
				maxnum <- struct{}{}
			}
			mg.Add(5)
			time.Sleep(time.Second * 3)
		}
	}()
	for {
		<-maxnum
		go func() {
			defer mg.Done()
			go myjobs()
		}()
	}
}
